<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ContactForm */

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha;
use frontend\assets\AppAsset;
use yii\widgets\MaskedInput;

AppAsset::register($this);
AppAsset::addScript($this,Yii::$app->request->baseUrl."/js/name.js");

$this->title = 'name';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
    <h1><?= Html::encode($this->title) ?></h1>
<?= yii\jui\DatePicker::widget(['name' => 'attributeName', 'clientOptions' => ['defaultDate' => '2014-01-01']]) ?>
    <p>
        If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
    </p>

    <div class="row">
        <div class="col-lg-5">
            <!-- 参数是一个数组的，会设置到activeForm的属性上面 -->
            <?php $form = ActiveForm::begin(['id' => 'nameform','enableAjaxValidation'=>true]); ?>

<!-- 
    
    checkbox()
    checkboxList()
    dropDownList()
    fileInput()
    hiddenInput()
    input()
    listBox()
    passwordInput()
    radio()
    radioList()
    textInput()
    textarea()

 -->
            <!-- 三个参数，第一个是model，第二个是属性，第三个是类的属性 -->
                <?= $form->field($model, 'name')->textInput(['autofocus' => true,'onChange'=>'nameModule.onchange()']) ?>

            <!-- 默认是textInput类型的 -->
                <?= $form->field($model, 'email') ?>

                <?= $form->field($model, 'test') ?>

                <!-- select框 -->
                <?= $form->field($model, 'age')->listBox(array_combine(range(30,100),range(30,100))) ?>
                <?= $form->field($model, 'age')->dropDownList(array_combine(range(30,100),range(30,100))) ?>

                <!-- 勾选框，复选框 -->
                <?= $form->field($model, 'age')->checkbox(['value'=>100]) ?>
                <?= $form->field($model, 'age')->checkboxList(array_combine(range(30,100),range(30,100))) ?>

                <!-- 格式的限制，可以用于手机号码，银行卡号码等等 -->
                <?= $form->field($model, 'age')->widget(MaskedInput::className(),['mask' => '999-999-9999',]) ?>

                <?= $form->field($model, 'age')->widget(MaskedInput::className(),['mask' => '999-999-9999',]) ?>

                <div class="form-group">
                    <?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
                </div>

            <?php ActiveForm::end(); ?>
        </div>
    </div>

</div>
<script>
<?php $this->beginBlock('test')?>
    var testonchange = function(){
        alert("ok");
    }

    $(function($) {
        $("#name-form").yiiActiveForm(
            {   
                "id": "nameform-test",
                "name": "test",
                "container": ".field-nameform-test",
                "input": "#nameform-test",
                "error": ".help-block.help-block-error",
                "validate": function (attribute, value, messages, deferred, $form) {
                    yii.validation.required(value, messages,{"message": "test cannot be blank."});
                }
            }
        );
    },[]);
<?php $this->endBlock()?>
</script>
<?php $this->registerJs($this->blocks['test'], \yii\web\View::POS_END,'99999999999');?>